#ifndef _RV_COMMON_H_
#define _RV_COMMON_H_

template<typename F>
struct _FINAL_ACTION
{
	_FINAL_ACTION(F f) : clean(f), isDiscard(false) {}
	~_FINAL_ACTION() { if (!isDiscard) clean(); }
	void discard() { isDiscard = true; }

	F clean;
	bool isDiscard;
};

template<typename F>
_FINAL_ACTION<F> finally(F f)
{
	return _FINAL_ACTION<F>(f);
}

#endif // _RV_COMMON_H_
